//
//  RBHomeVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/5/26.
//

#import "RBHomeVC.h"
#import <UINavigationController+FDFullscreenPopGesture.h>
#import "RBDefine.h"
#import "RBGradientView.h"
#import <Masonry.h>
#import <YYCategories.h>
#import "RBRefreshHeader.h"
#import "RBRefreshFooter.h"
#import "RBHomeBannerView.h"
#import "RBThemeConfig.h"
#import "RBGradientView.h"
#import "RBHomeNoticeView.h"
#import "RBCollectionReusableView.h"
#import "UIView+RBAdd.h"
#import "RBHomeListHeaderView.h"
#import "RBHomeAtyZoneShopView.h"
#import "RBHomeAtyZoneBrandView.h"
#import "RBHomeSecKillView.h"
#import "RBHomeHotRankCell.h"
#import "RBHomeGoodsRecView.h"
#import "RBHomeGuessCell.h"
#import "RBNoticeListVC.h"
#import "RBSearchVC.h"
#import "RBMsgVC.h"
#import "RBGroupVC.h"
#import "RBSecondKillVC.h"
#import "RBLuckyDrawVC.h"
#import "RBDaylySignVC.h"
#import "RBGetCouponVC.h"
#import "RBShopApplyVC.h"
#import "RBAppDelegateHelper.h"
#import "RBSplashVC.h"
#import "AppDelegate.h"
#import "RBHomeBannerResponse.h"
#import "NSString+RBAdd.h"
#import "RBUtils.h"
#import "RBHomeNoticeResponse.h"
#import "RBHomeGoodsRecResponse.h"
#import "RBHomeAtyZoneResponse.h"
#import "RBHomeGuessResponse.h"
#import "RBHomeHotResponse.h"
#import "RBBrandVC.h"
#import "RBGoodsDetailVC.h"
#import "RBHomeSeckillResponse.h" //显示秒杀
#import "RBHomeMessageResponse.h"
#import "RBNoticeDetailVC.h"
#import "RBShopDetailVC.h"
#import "RBWebVC.h"

@interface RBHomeVC ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property(nonatomic, strong)UIView *topBgView;

@property(nonatomic, strong)IBOutlet UIView *naviBarView;
@property(nonatomic, strong)IBOutlet UIButton *msgBtn;
@property(nonatomic, strong)IBOutlet UIView *msgDotView;

@property(nonatomic, strong)UICollectionView *collectionView;
@property(nonatomic, strong)NSMutableArray *dataSource;

@property(nonatomic, strong)RBHomeBannerView *bannerView;
@property(nonatomic, strong)IBOutlet UIView *menuView;
@property(nonatomic, strong)IBOutlet UIView *noticeView;
@property(nonatomic, strong)IBOutlet RBHomeNoticeView *noticeScrollView;

@property(nonatomic, strong)RBHomeBannerResponse *bannerResponse;
@property(nonatomic, strong) RBHomeNoticeResponse *noticeResponse;
@property(nonatomic, strong) RBHomeGoodsRecResponse *goodsRecResponse;
@property(nonatomic, strong) RBHomeAtyZoneResponse *atyZoneResponse;
@property(nonatomic, strong) RBHomeGuessResponse *guessResponse;
@property(nonatomic, strong) RBHomeHotResponse *hotResponse;
@property (nonatomic, strong) RBHomeSeckillResponse *seckillResponse;

@end

@implementation RBHomeVC

#pragma mark - Lifecycle

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    //
    if([[RBAccountManager getUserId] length] == 0){
        self.msgDotView.hidden = YES;
    } else {
        NSString *urlString = @"han_xiaoxi_noread";
        LCWeakSelf;
        [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
            
        } path:urlString post:YES log:YES responseClass:RBHomeMessageResponse.class desView:self.view showHud:NO showPlaceHolder:NO sucBlock:^(RBHomeMessageResponse *data) {
            
            if ([data.data isEqualToString:@"0"]) {
                weakSelf.msgDotView.hidden = YES;
            } else {
                weakSelf.msgDotView.hidden = NO;
            }
        } failBlock:^(RBHomeMessageResponse *data) {
            [weakSelf.view showTip:data.message completion:nil];
        } reloadBlock:nil];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
    [self getData];    
}

#pragma mark - Private

- (void)setup
{
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = [RBThemeConfig bgGrayColor];
    
    __weak typeof(self) weakSelf = self;
    AppDelegate *delegate = (AppDelegate *)UIApplication.sharedApplication.delegate;
    if (!delegate.splashShowed)
    {
        delegate.splashShowed = YES;
        [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
            
        } path:@"han_ad_qd" post:YES log:YES responseClass:RBSplashResponse.class desView:self.view showHud:NO showPlaceHolder:NO sucBlock:^(RBSplashResponse *data) {
            if(data.data.picurl.length)
            {
                RBSplashVC *vc = RBSplashVC.new;
                vc.response = data;
                [weakSelf.tabBarController presentVc:vc];
            }
        } failBlock:nil reloadBlock:nil];
    }
    
    self.topBgView.hidden = NO;
    [self.view addSubview:self.naviBarView];
    [self.naviBarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(kRBStatusBarHeight + 15);
        make.height.mas_equalTo(self.naviBarView.height);
    }];
    
    [self.menuView zoomSubViewsWithSelf];
    self.menuView.height = Zoom(self.menuView.height);
    [self.noticeView zoomSubViewsWithSelf];
    self.noticeView.height = Zoom(self.noticeView.height);
}

- (void)fillData
{
    __weak typeof(self) weakSelf = self;
    [self.dataSource removeAllObjects];
    
    self.bannerView.dataSource = ({
        NSMutableArray *arrayM = NSMutableArray.array;
        for (RBHomeBannerModel *model in self.bannerResponse.banner)
        {
            if (model.picurl)
            {
                [arrayM addObject:model.picurl];
            }
        }
        arrayM;
    });
    self.bannerView.selectBlock = ^(NSInteger index) {
        RBHomeBannerModel *model = weakSelf.bannerResponse.banner[index];
        if ([model.ad_type isEqualToString:@"1"]) { //活动
            RBNoticeDetailVC *vc = RBNoticeDetailVC.new;
            vc.id = model.linkurl;
            vc.hidesBottomBarWhenPushed = YES;
            [weakSelf.navigationController pushViewController:vc animated:YES];
        } else if ([model.ad_type isEqualToString:@"2"]) { //商品
            RBGoodsDetailVC *vc = RBGoodsDetailVC.new;
            vc.id = model.linkurl;
            vc.hidesBottomBarWhenPushed = YES;
            [weakSelf.navigationController pushViewController:vc animated:YES];
        } else if ([model.ad_type isEqualToString:@"3"]) { //店铺
            RBShopDetailVC *vc = RBShopDetailVC.new;
            vc.id = model.linkurl;
            vc.hidesBottomBarWhenPushed = YES;
            [weakSelf.navigationController pushViewController:vc animated:YES];
        } else if ([model.ad_type isEqualToString:@"4"]) { //外部链接
            RBWebVC *vc = RBWebVC.new;
            vc.urlString = model.linkurl;
            vc.titleString = @"详情";
            vc.hidesBottomBarWhenPushed = YES;
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }
    };
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerView = ({
            UIView *view = UIView.new;
            [view addSubview:self.bannerView];
            [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(Zoom(12));
                make.right.mas_equalTo(-Zoom(12));
                make.top.bottom.mas_equalTo(0);
            }];
            view;
        });
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, Zoom(160));
        group;
    })];
    
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerView = self.menuView;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, self.menuView.height);
        group;
    })];
    
    self.noticeScrollView.data = ({
        NSMutableArray *arrayM = NSMutableArray.array;
        for (RBHomeNoticeModel *model in self.noticeResponse.data)
        {
            [arrayM addObject:kRBNotNilString(model.title)];
        }
        arrayM;
    });
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerView = self.noticeView;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, self.noticeView.height);
        group.eventBlock = ^(id data) {
            
        };
        group;
    })];
    
    [self.dataSource addObject:[self marginWithHeight:Zoom(17) color:UIColor.clearColor topCorner:NO bottomCorner:NO cornerRadius:0]];
    
    [self.dataSource addObject:[self marginWithHeight:Zoom(30) color:UIColor.whiteColor topCorner:YES bottomCorner:NO cornerRadius:Zoom(30)]];
    
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, Zoom(27));
        group.headerView = ({
            RBHomeListHeaderView *view = RBHomeListHeaderView.new;
            view.backgroundColor = UIColor.whiteColor;
            view.title = @"活动专区";
            view;
        });
        group;
    })];
    
    [self.dataSource addObject:[self marginWithHeight:Zoom(20) color:UIColor.whiteColor topCorner:NO bottomCorner:NO cornerRadius:0]];
    
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, [RBHomeAtyZoneShopView suggestViewHeight]);
        group.headerView = ({
            RBHomeAtyZoneShopView *view = RBHomeAtyZoneShopView.new;
            view.data = self.atyZoneResponse.data;
            view;
        });
        group;
    })];
    
    [self.dataSource addObject:[self marginWithHeight:Zoom(44) color:UIColor.whiteColor topCorner:NO bottomCorner:NO cornerRadius:0]];
    
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, [RBHomeAtyZoneBrandView suggestViewHeight]);
        group.headerView = ({
            RBHomeAtyZoneBrandView *view = RBHomeAtyZoneBrandView.new;
            view.data = self.bannerResponse.brand;
            view.block = ^(NSInteger index) {
                RBBrandVC *vc = RBBrandVC.new;
                [weakSelf.navigationController pushViewController:vc animated:YES];
            };
            view;
        });
        group;
    })];
    
    [self.dataSource addObject:[self marginWithHeight:Zoom(32) color:UIColor.whiteColor topCorner:NO bottomCorner:NO cornerRadius:0]];
    
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, [RBHomeSecKillView suggestViewHeight]);
        group.headerView = ({
            RBHomeSecKillView *view = [RBHomeSecKillView view];
            [view receiveDataWith:self.seckillResponse.data];
            view.moreBlock = ^{
                RBSecondKillVC *vc = RBSecondKillVC.new;
                [weakSelf.navigationController pushViewController:vc animated:YES];
            };
            view;
        });
        group;
    })];
    
    [self.dataSource addObject:[self marginWithHeight:Zoom(7) color:UIColor.whiteColor topCorner:NO bottomCorner:NO cornerRadius:0]];
    
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, Zoom(45));
        group.headerView = ({
            RBHomeListHeaderView *view = RBHomeListHeaderView.new;
            view.backgroundColor = UIColor.whiteColor;
            view.title = @"人气排名";
            view;
        });
        group.cellModels = ({
            NSMutableArray *arrayM = NSMutableArray.array;
            for (RBHomeHotModel *model in self.hotResponse.data) {
                [arrayM addObject:({
                    RBCellModel *cellModel = RBCellModel.new;
                    cellModel.reuseCellIdentifier = NSStringFromClass(RBHomeHotRankCell.class);
                    cellModel.itemSize = CGSizeMake(kRBMainScreenWidth, Zoom(92));
                    cellModel.cellData = model;
                    cellModel.cellSelectBlock = ^(NSIndexPath *indexPath) {
                        RBGoodsDetailVC *vc = RBGoodsDetailVC.new;
                        vc.id = model.id;
                        [weakSelf.navigationController pushViewController:vc animated:YES];
                    };
                    cellModel;
                })];
            }
            arrayM;
        });
        group;
    })];
    
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, Zoom(57));
        group.headerView = ({
            UIColor *fromColor = UIColor.whiteColor;
            UIColor *toLor = [RBThemeConfig bgGrayColor];
            RBGradientView *gradientView = [RBGradientView gradientViewWithColors:@[fromColor,toLor] locations:@[@0,@1] vertical:YES];
            
            RBHomeListHeaderView *view = RBHomeListHeaderView.new;
            view.title = @"好物推荐";
            [gradientView addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(0);
            }];
            
            gradientView;
        });
        group;
    })];
    
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, [RBHomeGoodsRecView suggestViewHeight]);
        group.headerView = ({
            RBHomeGoodsRecView *view = RBHomeGoodsRecView.new;
            view.goods = self.goodsRecResponse.data;
            view;
        });
        group;
    })];
    
    [self.dataSource addObject:[self marginWithHeight:Zoom(20) color:UIColor.clearColor topCorner:NO bottomCorner:NO cornerRadius:0]];
    
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, Zoom(20));
        group.headerView = ({
            RBHomeListHeaderView *view = RBHomeListHeaderView.new;
            view.title = @"猜您喜欢";
            view;
        });
        group.minimumInteritemSpacing = [RBHomeGuessCell padding]-1;
        group.minimumLineSpacing = [RBHomeGuessCell padding]-1;
        group.sectionInset = UIEdgeInsetsMake([RBHomeGuessCell margin], [RBHomeGuessCell margin], [RBHomeGuessCell margin], [RBHomeGuessCell margin]);
        group.cellModels = ({
            NSMutableArray *arrayM = NSMutableArray.array;
            for (RBHomeGuessModel *model in self.guessResponse.data)
            {
                [arrayM addObject:({
                    RBCellModel *cellModel = RBCellModel.new;
                    cellModel.reuseCellIdentifier = NSStringFromClass(RBHomeGuessCell.class);
                    cellModel.itemSize = [RBHomeGuessCell suggestSize];
                    cellModel.cellData = model;
                    cellModel.cellSelectBlock = ^(NSIndexPath *indexPath) {
                        RBGoodsDetailVC *vc = [RBGoodsDetailVC new];
                        vc.id = model.id;
                        vc.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:vc animated:YES];
                    };
                    cellModel;
                })];
            }
            arrayM;
        });
        group;
    })];
    
    [self.collectionView reloadData];
}

#pragma mark - Network

- (void)getData
{
    [self.view hidePlaceHolder];
    [self.view showProgressWithText:nil];
    
    __weak typeof(self) weakSelf = self;
    dispatch_group_t group = dispatch_group_create();
    
    dispatch_group_enter(group);
    [self.defaultHm requestWithParam:^(NSMutableDictionary *dicM) {
        
    } log:YES post:YES cancelLastRequest:NO fileParam:nil fileProgress:nil responseClass:RBHomeBannerResponse.class pathName:@"han_ad_index" completion:^(RBHomeBannerResponse *response) {
        if (response.succeed)
        {
            weakSelf.bannerResponse = response;
        }
        dispatch_group_leave(group);
    }];
    
    dispatch_group_enter(group);
    [self.defaultHm requestWithParam:^(NSMutableDictionary *dicM) {
        
    } log:YES post:YES cancelLastRequest:NO fileParam:nil fileProgress:nil responseClass:RBHomeNoticeResponse.class pathName:@"han_index_gonggao" completion:^(RBHomeNoticeResponse *response) {
        if (response.succeed)
        {
            weakSelf.noticeResponse = response;
        }
        dispatch_group_leave(group);
    }];
    
    dispatch_group_enter(group);
    [self.defaultHm requestWithParam:^(NSMutableDictionary *dicM) {
        
    } log:YES post:YES cancelLastRequest:NO fileParam:nil fileProgress:nil responseClass:RBHomeSeckillResponse.class pathName:_Home_seckill completion:^(RBHomeSeckillResponse *response) {
        if (response.succeed)
        {
            weakSelf.seckillResponse = response;
        }
        dispatch_group_leave(group);
    }];
    
    dispatch_group_enter(group);
    [self.defaultHm requestWithParam:^(NSMutableDictionary *dicM) {
        
    } log:YES post:YES cancelLastRequest:NO fileParam:nil fileProgress:nil responseClass:RBHomeGoodsRecResponse.class pathName:@"han_index_haowu" completion:^(RBHomeGoodsRecResponse *response) {
        if (response.succeed)
        {
            weakSelf.goodsRecResponse = response;
        }
        dispatch_group_leave(group);
    }];
    
    dispatch_group_enter(group);
    [self.defaultHm requestWithParam:^(NSMutableDictionary *dicM) {
        
    } log:YES post:YES cancelLastRequest:NO fileParam:nil fileProgress:nil responseClass:RBHomeAtyZoneResponse.class pathName:@"han_index_huodong" completion:^(RBHomeAtyZoneResponse *response) {
        if (response.succeed)
        {
            weakSelf.atyZoneResponse = response;
        }
        dispatch_group_leave(group);
    }];
    
    dispatch_group_enter(group);
    [self.defaultHm requestWithParam:^(NSMutableDictionary *dicM) {
        
    } log:YES post:YES cancelLastRequest:NO fileParam:nil fileProgress:nil responseClass:RBHomeGuessResponse.class pathName:@"han_index_xihuan" completion:^(RBHomeGuessResponse *response) {
        if (response.succeed)
        {
            weakSelf.guessResponse = response;
        }
        dispatch_group_leave(group);
    }];
    
    dispatch_group_enter(group);
    [self.defaultHm requestWithParam:^(NSMutableDictionary *dicM) {
        
    } log:YES post:YES cancelLastRequest:NO fileParam:nil fileProgress:nil responseClass:RBHomeHotResponse.class pathName:@"han_index_renqi" completion:^(RBHomeHotResponse *response) {
        if (response.succeed)
        {
            weakSelf.hotResponse = response;
        }
        dispatch_group_leave(group);
    }];
    
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        [weakSelf.view hideHud];
        if (weakSelf.bannerResponse && weakSelf.noticeResponse && weakSelf.goodsRecResponse && weakSelf.guessResponse && weakSelf.hotResponse && weakSelf.seckillResponse)
        {
            [weakSelf fillData];
        }
        else
        {
            [weakSelf.view showPlaceHolder:@"请求失败\n点击刷新" tapBlock:^{
                [weakSelf getData];
            }];
        }
    });
}

#pragma mark - UICollectionViewDataSource & UICollectionViewDelegate

kRBCollectionViewDataSourceAndDelegate(self.dataSource);

#pragma mark - Event

- (IBAction)searchViewTapped:(id)sender
{
    if([[RBAccountManager getUserId] length] == 0){
        [RBAppDelegateHelper showLoginPageWithCompletion:^{
            
        }];
        return;
    }
    RBSearchVC *vc = RBSearchVC.new;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)msgViewTapped:(id)sender
{
    if([[RBAccountManager getUserId] length] == 0){
        [RBAppDelegateHelper showLoginPageWithCompletion:^{
            
        }];
    }
    else{
        RBMsgVC *vc = RBMsgVC.new;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (IBAction)menuBtnTapped:(UIButton *)btn
{
    if([[RBAccountManager getUserId] length] == 0){
        [RBAppDelegateHelper showLoginPageWithCompletion:^{
            
        }];
        return;
    }
    switch (btn.tag) {
        case 0:
        {
            RBLuckyDrawVC *vc = RBLuckyDrawVC.new;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            RBGroupVC *vc = RBGroupVC.new;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            RBDaylySignVC *vc = RBDaylySignVC.new;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:
        {
            RBGetCouponVC *vc = RBGetCouponVC.new;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 4:
        {
            RBShopApplyVC *vc = RBShopApplyVC.new;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}

- (IBAction)noticeViewTapped:(id)sender
{
    RBNoticeListVC *vc = RBNoticeListVC.new;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - Setter

#pragma mark - Getter

- (UIView *)topBgView
{
    if (!_topBgView)
    {
       
        self.topBgView = ({
            UIView *view = UIView.new;
            
            UIColor *fromColor = [UIColor colorWithHexString:@"#CADCFF"];
            UIColor *toLor = [RBThemeConfig bgGrayColor];
            RBGradientView *gradientView = [RBGradientView gradientViewWithColors:@[fromColor,fromColor,toLor] locations:@[@0,@0.8,@1] vertical:YES];
            [view addSubview:gradientView];
            [gradientView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(0);
            }];
            
            CGFloat height = 230+kRBStatusBarHeight;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.top.mas_equalTo(0);
                make.height.mas_equalTo(height);
            }];
            view;
        });
    }
    return _topBgView;
}

- (UICollectionView *)collectionView
{
    if (!_collectionView)
    {
        self.collectionView = ({
            UICollectionViewFlowLayout *layout = UICollectionViewFlowLayout.new;
            UICollectionView *view = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout];
            view.showsVerticalScrollIndicator = NO;
            view.showsHorizontalScrollIndicator = NO;
            view.dataSource = self;
            view.delegate = self;
            view.backgroundColor = UIColor.clearColor;
            kRBIgnoreScrollViewInsetsAdjust(view);
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(0);
                make.right.mas_equalTo(0);
                make.bottom.mas_equalTo(0);
                make.top.mas_equalTo(self.naviBarView.mas_bottom).offset(10);
            }];
            view;
        });
    }
    return _collectionView;
}

- (NSMutableArray *)dataSource
{
    if (!_dataSource)
    {
        self.dataSource = ({
            NSMutableArray *arrayM = NSMutableArray.array;
            arrayM;
        });
    }
    return _dataSource;
}

- (RBHomeBannerView *)bannerView
{
    if (!_bannerView)
    {
        self.bannerView = ({
            RBHomeBannerView *view = RBHomeBannerView.new;
            view;
        });
    }
    return _bannerView;
}

- (RBGroupModel *)marginWithHeight: (CGFloat)height color: (UIColor *)color topCorner: (BOOL)topCorner bottomCorner: (BOOL)bottomCorner cornerRadius: (CGFloat)cornerRadius
{
    RBGroupModel *group = RBGroupModel.new;
    group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth,height);
    group.headerView = ({
        UIView *view = UIView.new;
        view.size = group.headerReferenceSize;
        view.backgroundColor = color;
        if (topCorner)
        {
            [view setRounderWithRectCorner:UIRectCornerTopLeft | UIRectCornerTopRight radius:cornerRadius];
        }
        if (bottomCorner)
        {
            [view setRounderWithRectCorner:UIRectCornerBottomLeft | UIRectCornerBottomRight radius:cornerRadius];
        }
        view;
    });
    group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
    return group;
}

@end
